import JSEncrypt from 'jsencrypt'

// RSA加密公钥
const DEFAULT_PUBLIC_KEY = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCafARGOzSb8LZd/NopBCKcIkRY0Iq4MjpkzxjI/fXAeyKN/ay+PaQcNCSILUj5u0vbNpyZRp/BjimsxtXjXgPJZwzdk+AdLgFbhI2hC6mLVgDPVAdu4glktMvAFKiWOlrjqHxOdedd2U6vJ54kKc7EZEaTiTfyD/uu7NUuD1a88QIDAQAB`;

/**
 * 公钥加密
 * @param {*} data 
 * @param {*} publicKey 
 * @returns 
 */
export const encrypt = (data, publicKey = null) => {
    const jseNcrypt = new JSEncrypt()
    jseNcrypt.setPublicKey(!publicKey ? DEFAULT_PUBLIC_KEY : publicKey)
    return jseNcrypt.encrypt(data)
}